package edu.xupt.ediction.slice;

import edu.xust.ediction.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Button;
import ohos.agp.components.Component;
import ohos.agp.components.TextField;
import ohos.agp.window.dialog.ToastDialog;

public class MainAbilitySlice extends AbilitySlice {
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);

        String username="songci";
        String passwd="123456";
        //获取用户名
        TextField tf_account =(TextField)this.findComponentById(ResourceTable.Id_text_account);
        //获取密码
        TextField tf_password =(TextField)this.findComponentById(ResourceTable.Id_text_password);
        //  获取注册按钮
        Button button_login = (Button) this.findComponentById(ResourceTable.Id_btn_login);
        // 设置注册按钮的单击事件
        button_login.setClickedListener(component -> {
            String account = tf_account.getText();
            String password = tf_password.getText();
            if(account.equals(username)&&password.equals(passwd)){
               new ToastDialog(getAbility()).setContentText("登录成功！").setDuration(2500).show();
               present(new SearchAbilitySlice(),new Intent());
            }else {
                new ToastDialog(getAbility()).setContentText("登录失败！用户名或密码错误！！").setDuration(2500).show();
            }
        });
       // button_login.setClickedListener(this::ClickedListenerButtonLogin);
        //  获取注册按钮
        Button button_sign = (Button) this.findComponentById(ResourceTable.Id_btn_sign);
        // 设置按钮的单击事件
        button_sign.setClickedListener(this::ClickedListenerButtonSign);
    }

    private void ClickedListenerButtonSign(Component component) {
        // 同一个Ability里页面之间的跳转
        Intent intent = new Intent();
        this.present(new SignAbilitySlice(),intent);
    }

//    private void ClickedListenerButtonLogin(Component component) {
//        // 同一个Ability里页面之间的跳转
//        Intent intent = new Intent();
//        this.present(new SearchAbilitySlice(),intent);
//    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
